package netty.test5ZeroCopy;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

/**
 * 新的io服务端
 */
public class NewIoServer {
    public static void main(String[] args) throws IOException {
        InetSocketAddress address=new InetSocketAddress(7003);
        ServerSocketChannel serverSocketChannel=ServerSocketChannel.open();
        ServerSocket serverSocket = serverSocketChannel.socket();
        serverSocket.bind(address);
        //1,创建一个buffer
        ByteBuffer byteBuffer = ByteBuffer.allocate(4096);
        while (true){

            try {
                SocketChannel socketChannel = serverSocketChannel.accept();
                int readCount=0;
                while (-1 !=readCount){
                    readCount=socketChannel.read(byteBuffer);

                }
            } catch (IOException e) {
                e.printStackTrace();
                break;
            }
            //将buffer倒带(相当于将postion置为0，mark清除，后面可以继续用这个buffer)
            byteBuffer.rewind();
            //下面就不处理了，这里就是观察下   数据传输过来花了多少时间
        }


    }
}
